/*
 *    Copyright (c) 2018-2025, boss All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the boss developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: boss
 */
package com.hopes.bizz.poll.monitor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hopes.bizz.poll.monitor.entity.PollMonitorSiteEntity;
import com.hopes.bizz.poll.monitor.entity.PollMonitorTypeEntity;
import com.hopes.bizz.poll.monitor.mapper.PollMonitorTypeMapper;
import com.hopes.bizz.poll.monitor.service.PollMonitorSiteService;
import com.hopes.bizz.poll.monitor.service.PollMonitorTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 监控站点类型
 *
 * @author daijie
 * @date 2023-09-18 17:33:03
 */
@Service
public class PollMonitorTypeServiceImpl extends ServiceImpl<PollMonitorTypeMapper, PollMonitorTypeEntity> implements PollMonitorTypeService {

    @Autowired
    @Lazy
    private PollMonitorSiteService pollMonitorSiteService;

    @Override
    public List<Integer> getMonitorTypeByMain(Integer monitorTypeMain) {
        return this.getBaseMapper().getMonitorTypeByMain(monitorTypeMain);
    }

    @Override
    public Integer getMonitorTypeMainByType(Integer type) {
        LambdaQueryWrapper<PollMonitorTypeEntity> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(PollMonitorTypeEntity::getMonitorType, type);

        return this.getBaseMapper().selectOne(wrapper).getMonitorTypeMain();
    }

    @Override
    public PollMonitorTypeEntity getBySiteId(Long siteId) {
        PollMonitorSiteEntity siteEntity = pollMonitorSiteService.getById(siteId);

        LambdaQueryWrapper<PollMonitorTypeEntity> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(PollMonitorTypeEntity::getMonitorType, siteEntity.getMonitorType());

        return this.getOne(wrapper);
    }
}